//
//  UISwitchViewController.swift
//  DemoUI
//
//  Created by 白瑾浩 on 2022/1/6.
//

import Foundation
import UIKit

class UISwitchViewController:UIViewController{
    
    override func viewDidLoad() {
        super.viewDidLoad()
        self.view.backgroundColor = .white
        let swi = UISwitch()
        swi.center = CGPoint(x: 100, y: 100)
        //设置开启状态的颜色
        swi.onTintColor = UIColor.green
        //设置普通状态的颜色
        swi.tintColor = UIColor.red
        //设置开关滑块的颜色
        swi.thumbTintColor = UIColor.purple
        //设置开关初始状态
        swi.isOn = true
        //开关状态的监听
        swi.addTarget(self, action: #selector(change(_:)), for: UIControl.Event.valueChanged)
        
        self.view.addSubview( swi )
        
    }
    //ui开关状态
    @objc func change(_ swi: UISwitch ){
        print( "开关状态：\(swi.isOn)" )
    }
    
    
}
